package dianmobile.eistarandroid.network.request;

import android.content.Context;

import com.android.volley.Response;

import org.xmlpull.v1.XmlPullParser;

import java.util.Map;

import dianmobile.eistarandroid.utils.ConstantsData;

/**
 * Created by dianmobile_yy on 15/10/27.
 */
public class MailContentRequest extends ByhhAndroidRequest {

    public MailContentRequest(int method, String url, Map<String, String> params, RequestCallback callback, Response.ErrorListener errorListener) {
        super(method, url, params, callback, errorListener);
    }

    public static void execute(Context context, Map<String, String> params, RequestCallback callback) {
        executeSuper(context, RequestType.MAIL_CONTENT, params, callback);
    }

    @Override
    protected void parseXmlToMap(XmlPullParser parser, Map<String, Object> result) {

        String content = "";
        String TAG_CONTENT = "content";

        try {
            int event = parser.getEventType();
            while (event != XmlPullParser.END_DOCUMENT) {
                switch (event) {
                    case XmlPullParser.START_TAG:
                        String tagName = parser.getName();
                        if(TAG_CONTENT.equals(tagName)) {
                            content = parser.nextText();
                        }
                        break;
                    default:
                        break;
                }
                event = parser.next();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        String[] strings = content.split("\\.\\*|--\n");

        if (strings.length>2){
            result.put(ConstantsData.RESULT_DATA, strings[1]);
        } else {
            result.put(ConstantsData.RESULT_DATA, content);
        }
    }
}
